package mini.reanimate;

import world.Sound;
import hubol.ClickableRectangle;
import hubol.Sprite;

public class Right extends Screen{
	private final float SCALE = 1.025f;
	private int shakeCounter = 0;
	
	private final ClickableRectangle[] PETAL = new ClickableRectangle[]{new ClickableRectangle(93, 103, 59, 75), new ClickableRectangle(333, 28, 44, 52), new ClickableRectangle(615, 98, 72, 39)};
	private final ClickableRectangle INSERT = new ClickableRectangle(581, 276, 70, 29);
	private final ClickableRectangle FLAME = new ClickableRectangle(520, 321, 125, 63);
	private final ClickableRectangle LEFT = new ClickableRectangle(5, 18, 67, 432);


	public Right() {
		super(11, "right");
		// TODO Auto-generated constructor stub
	}

	@Override
	public void step() {
		if (!busy()){
			//petals
			for (int i=0; i<3; i++){
				if (!Reanimate.me.gotPetal[i]){
					if (PETAL[i].moused()){
						Reanimate.me.setMouse(2);
						if (PETAL[i].clicked()){
							Reanimate.me.gotPetal[i] = true;
							Reanimate.me.petals++;
							Reanimate.me.point(Reanimate.me.pPetals);
							new Spam("petalget", 5+Reanimate.me.petals);
							
							//TODO 1-second song
							Reanimate.me.BOGUS.dance(60);
							
							return;
						}
					}
				}
			}
			
			//insert money
			if (Reanimate.me.money){
				if (INSERT.moused()){
					Reanimate.me.setMouse(Reanimate.me.sMoney);
					if (INSERT.clicked()){
						Reanimate.me.money = false;
						Reanimate.me.spentMoney = true;
						
						new Spam("use", 5);
						Sound.playPitched("flamebuy");
						return;
					}
				}
			}
			
			//take flamethrower
			if (Reanimate.me.spentMoney && !Reanimate.me.flame){
				if (FLAME.moused()){
					Reanimate.me.setMouse(2);
					if (FLAME.clicked()){
						Reanimate.me.flame = true;
						
						Reanimate.me.BOGUS.jump();
						
						Reanimate.me.point(Reanimate.me.pFlame);
						new Spam("get", 5);
						Sound.playPitched("flameequip");
						return;
					}
				}
			}
			
			//go left
			if (LEFT.moused()){
				Reanimate.me.setMouse(1);
				if (LEFT.clicked()){
					Reanimate.me.BOGUS.left();
					return;
				}
			}
		}
		
	}

	@Override
	public void enter() {
		if (Reanimate.me.gotMoney)
			Reanimate.me.on(4);
	}

	@Override
	public void leave() {
		Reanimate.me.off(4);
	}
	
	public void scene(Sprite sprite, int img, double x, double y){
		sprite.render(img, x + s[shakeCounter].x, y + s[shakeCounter].y, SCALE, SCALE, 0);
		shakeCounter++;
	}
	
	public void scene(Sprite sprite, int img){
		scene(sprite, img, 432, 243);
	}
	
	public void scene(int img){
		scene(sprite[0], img);
	}

	@Override
	public boolean background() {
		shakeCounter = 0;
		for (int i=0; i<6; i++)
			scene(i);
		if (Reanimate.me.spentMoney && !Reanimate.me.flame)
			scene(6);
		for (int i=0; i<3; i++){
			if (!Reanimate.me.gotPetal[i])
				scene(8 + i);
		}
		
		return true;
	}

	@Override
	public void foreground() {
		scene(7);
	}

	@Override
	public void bogusLand() {
		// TODO Auto-generated method stub
		
	}

}
